package com.ruowei.modules.foodOrder.repository;

import com.ruowei.common.repository.BaseRepository;
import com.ruowei.modules.foodOrder.domain.QShoppingCart;
import com.ruowei.modules.foodOrder.domain.ShoppingCart;

import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * Spring Data  repository for the ShoppingCart entity.
 */
@Repository
public interface ShoppingCartRepository extends BaseRepository<Long, ShoppingCart, QShoppingCart> {

    Optional<ShoppingCart> findByMemberCode(String memberCode);

    List<ShoppingCart> findAllByMemberCode(String openId);

    @Query(value = "select DISTINCT * from shopping_cart where member_code=? group by merchant_code", nativeQuery = true)
    List<ShoppingCart> findGroupByMerchantCode(String openId);

    List<ShoppingCart> findAllByMemberCodeAndMerchantCode(String openId, String merchantCode);

    Optional<ShoppingCart> findByCartCode(String cartCode);

    Optional<ShoppingCart> deleteBySkuCodeAndMemberCode(String skuCode,String memberCode);

    Optional<ShoppingCart> findBySkuCodeAndMerchandiseCodeAndMerchantCodeAndMemberCode(String skuCode,String merchandiseCode,String merchantCode,String memberCode);
}
